package com.helloandroid

import android.app.Activity
import android.content.Intent
import com.business.Analyse
import com.business.AnalyseKey
import com.helloandroid.base.BaseFragment
import com.helloandroid.dialogs.AwardDialog
import com.helloandroid.tools.NetWorkUtil
import com.helloandroid.vo.TaskInfo
import com.helloandroid.vo.Type
import com.helloandroid.vo.ZhuanDataItem

abstract class BaseZhuanFragment: BaseFragment() {
    companion object {
        // 所有的数据
        val dataLst = ArrayList<ZhuanDataItem>()
        init {
            dataLst.add(ZhuanDataItem(
                    taskId = Type.Shoucitixian.value,
                    resIcon = R.drawable.dd_zhuan_tx_icon,
                    title = "首次提现",
                    coin = 60,
                    desc = "首次提现成功,立即奖励60金币.",
                    type = Type.Shoucitixian,
                    refresh = false,
                    target = 1
            ))

            dataLst.add(ZhuanDataItem(
                    taskId = Type.BuShu.value,
                    resIcon = R.drawable.dd_zhuan_mubiao_icon,
                    title = "目标步数",
                    coin = 60,
                    desc = "每天步数达标,即可领取金币.",
                    type = Type.BuShu,
                    target = 6000
            ))

            dataLst.add(ZhuanDataItem(
                    taskId = Type.BangdingWX.value,
                    resIcon = R.drawable.dd_zhuan_wx_icon,
                    title = "绑定微信",
                    coin = 80,
                    desc = "绑定微信和好友一起运动赚钱吧.",
                    type = Type.BangdingWX,
                    refresh = false,
                    target = 1
            ))

//            dataLst.add(ZhuanDataItem(
//                    taskId = Type.Share.value,
//                    resIcon = R.drawable.dd_zhuan_share_icon,
//                    title = "每日分享",
//                    coin = 30,
//                    desc = "邀请好友一起运动赚钱吧.",
//                    type = Type.Share,
//                    target = 1
//            ))

            dataLst.add(ZhuanDataItem(
                    taskId = Type.TianTianHongBao.value,
                    resIcon = R.drawable.dd_zhuan_hongbaosai_icon,
                    title ="天天红包赛",
                    coin = 30,
                    desc="走路瓜分现金红包.",
                    type = Type.TianTianHongBao,
                    target = 1
            ))

            dataLst.add(ZhuanDataItem(
                    taskId = Type.TianTianYunDong.value,
                    resIcon = R.drawable.dd_zhuan_yundong_icon,
                    title = "每日运动",
                    coin = 20,
                    desc = "每天动一动,收获健康与金币.",
                    type = Type.TianTianYunDong,
                    target = 1
            ))

            dataLst.add(ZhuanDataItem(
                    taskId = Type.ViewVideo.value,
                    resIcon = R.drawable.dd_zhuan_video_icon,
                    title = "看视频领金币",
                    coin = 40,
                    desc = "看视频免费领取金币.",
                    type = Type.ViewVideo,
                    target = 5
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.HeShui.value,
                    resIcon = R.drawable.dd_zhuan_heshui_icon,
                    title = "喝水打卡",
                    coin = 20,
                    desc = "喝水打卡就能赚钱.",
                    type = Type.HeShui,
                    target = 1
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.ZhuanPan.value,
                    resIcon = R.drawable.dd_zhuan_zhuanpan_icon,
                    title = "玩转盘",
                    coin = 50,
                    desc = "苹果、华为等各种手机等你来拿.",
                    type = Type.ZhuanPan,
                    target = 5
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.ChengYu.value,
                    resIcon = R.drawable.dd_zhuan_chengyu_icon,
                    title = "成语闯关",
                    coin = 40,
                    desc = "苹果、华为等各种手机等你来拿.",
                    type = Type.ChengYu,
                    target = 10
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.HongBaoYu.value,
                    resIcon = R.drawable.dd_zhuan_hongbaoyu_icon,
                    title = "完成红包雨",
                    coin = 40,
                    desc = "满屏红包等你来拆.",
                    type = Type.HongBaoYu,
                    target = 3
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.JiFuZi.value,
                    resIcon = R.drawable.dd_zhuan_jifu_icon,
                    title ="积福字",
                    coin = 30,
                    desc="积福字获取现金奖励.",
                    type = Type.JiFuZi,
                    target = 3
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.ZaoWanDaKa.value,
                    resIcon = R.drawable.dd_zhuan_zaowan_icon,
                    title = "早晚打卡",
                    coin = 30,
                    desc = "早晚打卡获取奖励.",
                    type = Type.ZaoWanDaKa,
                    target = 1
            ))
            dataLst.add(ZhuanDataItem(
                    taskId = Type.ChiFan.value,
                    resIcon = R.drawable.dd_zhuan_chifan_icon,
                    title = "餐补打卡",
                    coin = 30,
                    desc = "按时吃饭身体好,还能得奖励.",
                    type = Type.ChiFan,
                    target = 1
            ))
        }
    }
    val localDataLst = ArrayList<ZhuanDataItem>()
    var isReady = false
    var mInfo: TaskInfo? = null

    fun <T : Activity> jumpTo(clz: Class<T>) {
        startActivity(Intent(requireActivity(), clz))
    }

    fun getAward(item: ZhuanDataItem) {
        if (!NetWorkUtil.networkConnected()) {
            AppUtil.toast("请打开网络!")
            return
        }

        val reason = when(item.type) {
            Type.Shoucitixian -> {
                Analyse.report(AnalyseKey.Zhuan_Shoucitixian)
                AnalyseKey.Zhuan_Shoucitixian_Video
            }
            Type.BuShu -> {
                Analyse.report(AnalyseKey.Zhuan_BuShu)
                AnalyseKey.Zhuan_BuShu_Video
            }
            Type.BangdingWX -> {
                Analyse.report(AnalyseKey.Zhuan_Bindwx)
                AnalyseKey.Zhuan_Bindwx_Video
            }
            Type.Share -> {
                Analyse.report(AnalyseKey.Zhuan_Share)
                AnalyseKey.Zhuan_Share_Video
            }
            Type.TianTianHongBao -> {
                Analyse.report(AnalyseKey.Zhuan_TTHBS)
                AnalyseKey.Zhuan_TTHBS_Video
            }
            Type.ZaoWanDaKa -> {
                Analyse.report(AnalyseKey.Zhuan_ZaoWanDaKa)
                AnalyseKey.Zhuan_ZaoWanDaKa_Video
            }
            Type.ChiFan -> {
                Analyse.report(AnalyseKey.Zhuan_ZaoWanDaKa)
                AnalyseKey.Zhuan_ZaoWanDaKa_Video
            }
            Type.TianTianYunDong -> {
                Analyse.report(AnalyseKey.Zhuan_Tiantianyundong)
                AnalyseKey.Zhuan_Tiantianyundong_Video
            }
            Type.ViewVideo -> {
                Analyse.report(AnalyseKey.Zhuan_ViewVideo)
                AnalyseKey.Zhuan_ViewVideo_Video
            }
            Type.HeShui -> {
                Analyse.report(AnalyseKey.Zhuan_HeShui)
                AnalyseKey.Zhuan_HeShui_Video
            }
            Type.ZhuanPan -> {
                Analyse.report(AnalyseKey.Zhuan_ZhuanPan)
                AnalyseKey.Zhuan_ZhuanPan_Video
            }
            Type.ChengYu -> {
                Analyse.report(AnalyseKey.Zhuan_Cy)
                AnalyseKey.Zhuan_Cy_Video
            }
            Type.HongBaoYu -> {
                Analyse.report(AnalyseKey.Zhuan_Hby)
                AnalyseKey.Zhuan_Hby_Video
            }
            Type.JiFuZi->{
                Analyse.report(AnalyseKey.Zhuan_JiFu)
                AnalyseKey.Zhuan_JiFu_Video
            }
            else -> {
                "unknow"
            }
        }

        //  直接给奖励
        val awardCoin = item.coin
        AppUtil.appViewModel().zhuanGetAward(item.type, awardCoin)
        mInfo?.setStateToGeted(item.type)

        // 更新ui
        initUI()

        // 弹框进行奖励
        val dialog = AwardDialog(this, awardCoin)
        dialog.reasonKey = reason
        dialog.show()
    }

    abstract fun initUI()
    abstract fun switchToZouFragment()
    abstract fun swithToWodeFragment()
}